using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace CubeTimer
{
  public class MonCal : MonthCalendar
  {
    private readonly List<DateTime> m_higlightDates = new List<DateTime>();
    public event EventHandler<DateSelectedEvetArgs> DateWasSelected;

    public void Init(Dictionary<string, DateTime> highlightedDays)
    {
      m_higlightDates.Clear();
      int count = 0;
      foreach (KeyValuePair<string, DateTime> day in highlightedDays)
      {
        DateTime date = DateTime.Parse(day.Value.ToShortDateString());
        if (count++ == 0) MinDate = date;
        AddBoldedDate(date);
        m_higlightDates.Add(day.Value);
      }
      MaxDate = DateTime.Today;
    }

    protected override void OnDateSelected(DateRangeEventArgs drevent)
    {
      foreach (DateTime date in m_higlightDates)
        if (date.DayOfYear == drevent.End.DayOfYear)
          InvokeDateWasSelected(new DateSelectedEvetArgs(drevent.End));
    }

    private void InvokeDateWasSelected(DateSelectedEvetArgs e)
    {
      EventHandler<DateSelectedEvetArgs> dateWasSelectedHandler = DateWasSelected;
      if (dateWasSelectedHandler != null) dateWasSelectedHandler(this, e);
    }
  }

  public class DateSelectedEvetArgs : EventArgs
  {
    public readonly DateTime Date;

    public DateSelectedEvetArgs(DateTime date)
    {
      Date = date;
    }
  }
}